﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;
using DTO;
using UTIL;

namespace DAO
{
    public class HinhMauThietKeDao
    {
        public static int LayIDTheoHinh(String tenHinh)
        {
            // tao ket noi CSDL 
            SqlConnection cnn = DataConnector.MakeConnection();

            String sql = "select ID from hinhmau where hinh like '%" + tenHinh + "%'";
            SqlCommand cmd = new SqlCommand(sql, cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                int a = (int)dr[0];
                cnn.Close();
                return a;
            }

            cnn.Close();
            return 0;

        }

        public static String LayHinhTheoID(int id)
        {
            // tao ket noi CSDL 
            SqlConnection cnn = DataConnector.MakeConnection();

            String sql = "select hinh from hinhmau where ID = " + id;
            SqlCommand cmd = new SqlCommand(sql, cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                String a = (String)dr[0];
                cnn.Close();
                return a;
            }

            cnn.Close();
            return "";

        }
    }
}
